package com.siegelion.plugin;

import android.app.Activity;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugin.common.BasicMessageChannel;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.StandardMessageCodec;
import io.flutter.view.FlutterView;

public class MethodChannelTool  implements BasicMessageChannel.MessageHandler<Object>{

    private static BasicMessageChannel<Object> methodChannel;
    private Activity activity;

    private MethodChannelTool(Activity activity) {
        this.activity = activity;
    }

    public static void registerWith(FlutterEngine flutterEngine,Activity activity1) {
        methodChannel = new BasicMessageChannel<Object>(flutterEngine.getDartExecutor().getBinaryMessenger(), "MethodChannelTool", StandardMessageCodec.INSTANCE);
        MethodChannelTool instance = new MethodChannelTool(activity1);
        methodChannel.setMessageHandler(instance);
    }

   /* @Override
    public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
        if (methodCall.method.equals("gotoDestinationSearchPage")) {
           // EventBus.getDefault().post(new GotoDestinationSearchPageEvent());
            result.success(200);
        } else if (methodCall.method.equals("gotoSpeakPage")) {
            if(methodCall.argument("pageType").equals("destination")){
             //   EventBus.getDefault().post(new GotoSpeakDestinationPageEvent(methodCall.argument("pageType")));
            }if(methodCall.argument("pageType").equals("travel")){
             //   EventBus.getDefault().post(new GotoSpeakTravelPageEvent(methodCall.argument("pageType")));
            }
            result.success(200);
        } else if (methodCall.method.equals("gotoWebView")) {
            //WebViewImpl.getInstance().gotoWebView(methodCall.argument("url"));
            result.success(200);
        }else if (methodCall.method.equals("gotoTravelSearchPage")){
            //EventBus.getDefault().post(new GotoTravelSearchPageEvent());
            result.success(200);
        }
        else {
            result.notImplemented();
        }
    }

    */

    @Override
    public void onMessage(@Nullable Object message, @NonNull BasicMessageChannel.Reply<Object> reply) {
        if (message.equals("test")){
            System.out.println("111111111111111111111111111111111111111111111111111");
        }
    }
}
